from typing import *


class Solution:

    def sumDistance(self, nums: List[int], s: str, d: int) -> int:
        for i in range(len(nums)):
            nums[i] += d if s[i] == 'R' else -d
        nums.sort()
        ans, s = 0, nums[0]
        for i in range(1, len(nums)):
            ans += nums[i] * i - s
            s += nums[i]
        return ans % 1000000007
    

class Solution:

    def sumDistance(self, nums: List[int], s: str, d: int) -> int:
        for i in range(len(nums)):
            nums[i] += d if s[i] == 'R' else -d
        nums.sort()
        ans, s = 0, nums[0]
        for i in range(1, len(nums)):
            ans += (nums[i] - nums[i - 1]) * i * (len(nums) - i)
        return ans % 1000000007

s = Solution()
print(s.sumDistance(nums=[-2, 0, 2], s="RLL", d=3))
